import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/utils/config.dart';
import 'package:provider/provider.dart';

class ItemBean {
  //距离
  String distance;

  //运营中心名称
  String title;

  //省
  String province;

  //市
  String city;

  //区
  String district;

  //详细地址
  String detailedAddress;

  //电话
  String telephone;

  ItemBean(this.distance, this.title, this.province, this.city, this.district, this.detailedAddress,
      this.telephone);
}

class OperationCenterCard extends StatelessWidget {
  final ItemBean bean;
  final Function() onClick;
  final ValueNotifier<ItemBean> value = ValueNotifier(null);
  final Function() goTo;
  final bool showGoTo;
  final Function() onSelect;

  OperationCenterCard(
      {Key key, this.bean, this.onClick, this.goTo, this.showGoTo = true, this.onSelect})
      : super(key: key);

  void upOperation(ItemBean updata) {
    value.value = updata;
  }

  @override
  Widget build(BuildContext context) {
    value.value = bean;
    return ValueListenableProvider<ItemBean>.value(
      value: value,
      builder: (context, _) {
        ItemBean bean = context.watch<ItemBean>();
        return Card(
          elevation: 5,
          child: InkWell(
            onTap: onSelect,
            child: Container(
              child: Padding(
                padding: EdgeInsets.only(left: 20.w, right: 20.w),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Padding(
                      padding: EdgeInsets.only(top: 40.h),
                      child: Row(
                        children: [
                          Expanded(
                              child: Text(
                            '距离您最近的服务中心',
                            style: TextStyle(
                              fontSize: 24.sp,
                              color: Color(0xFFFCAD08),
                            ),
                          )),
                          Text(
                            bean.distance,
                            style: TextStyle(
                              fontSize: 24.sp,
                              color: Color(0xFFFCAD08),
                            ),
                          ),
                        ],
                      ),
                    ),
                    InkWell(
                      onTap: onClick,
                      child: Container(
                        margin: EdgeInsets.only(top: 30.h, bottom: 30.h),
                        child: Row(
                          children: [
                            Expanded(
                              child: Text(
                                bean.title,
                                style: TextStyle(
                                  fontSize: 28.sp,
                                  color: Color(0xFF333333),
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                            showGoTo
                                ? Image.asset(
                                    'images/mine_right.png',
                                    width: 30.w,
                                  )
                                : Constants.empty,
                          ],
                        ),
                      ),
                    ),
                    Row(
                      children: [
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                '${bean.province} ${bean.city} ${bean.district}',
                                style: TextStyle(
                                  fontSize: 24.sp,
                                  color: Color(0xFF333333),
                                ),
                              ),
                              Text(
                                bean.detailedAddress,
                                style: TextStyle(
                                  fontSize: 24.sp,
                                  color: Color(0xFF333333),
                                ),
                              ),
                            ],
                          ),
                        ),
                        showGoTo
                            ? GestureDetector(
                                onTap: goTo,
                                child: Text(
                                  '到这里去',
                                  style: TextStyle(
                                    fontSize: 24.sp,
                                    color: Color(0xff0cabcb),
                                  ),
                                ),
                              )
                            : Constants.empty
                      ],
                    ),
                    Padding(
                      padding: EdgeInsets.only(top: 30.h, bottom: 30.h),
                      child: RichText(
                          text: TextSpan(
                        children: [
                          TextSpan(
                            text: '联系电话：',
                            style: TextStyle(
                              fontSize: 28.sp,
                              color: Color(0xff333333),
                            ),
                          ),
                          TextSpan(
                              text: bean.telephone,
                              style: TextStyle(
                                fontWeight: FontWeight.bold,
                                fontSize: 28.sp,
                                color: Color(0xff333333),
                              ))
                        ],
                      )),
                    )
                  ],
                ),
              ),
            ),
          ),
        );
      },
    );
  }
}
